home *** CD-ROM | disk | FTP | other *** search
/ Loadstar 18 / 018.d81 / pps #41 < prev    next >
Text File  |  2022-08-26  |  6KB  |  350 lines

  1. ======================================
  2.   PEEKs, POKEs, and SYSes, Part 41
  3.  
  4.     by Alan Gardner & Jim Weiler
  5. ======================================
  6.  
  7.          -----------------
  8.          ENVELOPE, or ADSR
  9.          -----------------
  10.  
  11.   I hate acronyms.  Don't you?
  12.  
  13. Today's acronym is ADSR.  It stands
  14.  
  15. for Attack/Decay/Sustain/Release.
  16.  
  17. This is the ONLY time I will use it's
  18.  
  19. full name, so please read it a couple
  20.  
  21. times before continuing.
  22.  
  23.                 ----
  24.  
  25.   An envelope is a way to picture
  26.  
  27. the volume of any sound as time
  28.  
  29. passes.  Here's a graph of a
  30.  
  31. hypothetical envelope of rolling
  32.  
  33. thunder:
  34.  
  35. v !    ...
  36. o !   .   ..
  37. l !  .      .   ..
  38. u ! .        ...  ...        ..
  39. m !.                 ........  .....
  40. e +----------------------------------
  41.        1 sec        2 sec       3 sec
  42.  
  43.   Every sound has a volume envelope.
  44.  
  45. Starting from silence, the volume
  46.  
  47. rises to some peak level and then dies
  48.  
  49. back to silence.
  50.  
  51.   The envelopes of most natural
  52.  
  53. sounds are very complicated, but
  54.  
  55. musical instruments tend to have
  56.  
  57. simpler envelopes.  ADSR was designed
  58.  
  59. to describe this simpler type of
  60.  
  61. envelope.
  62.  
  63.   A musical tone will start from
  64.  
  65. silence and rise quickly to a peak
  66.  
  67. volume.  If the tone is from a wind,
  68.  
  69. reed, or bowed instrument (flute,
  70.  
  71. trumpet, violin) the tone will stay
  72.  
  73. at or near that peak volume as long
  74.  
  75. as the note is being played. Then it
  76.  
  77. will gradually die down to silence
  78.  
  79. again.
  80.  
  81.   If the tone is from a plucked or
  82.  
  83. struck instrument (guitar, xylophone,
  84.  
  85. piano) the tone will immediately
  86.  
  87. drop in volume and remain at that
  88.  
  89. intermediate volume for a while.
  90.  
  91. Then it will gradually die down to
  92.  
  93. silence again.
  94.  
  95.   Of course, real instrument's
  96.  
  97. envelopes aren't quite this simple,
  98.  
  99. but you can achieve reasonable
  100.  
  101. approximations using envelopes much
  102.  
  103. like these:
  104.  
  105.  organ      violin      piano
  106. .......      ...         ..
  107. .     .     .   .       .  .
  108. .     .     .    .      .   ....
  109. .      .   .      .     .       .
  110. .      .   .       .   .         .
  111. .      .  .         .  .          .
  112.  
  113.  
  114.   The organ produces full volume
  115.  
  116. sound as soon as you press a key and
  117.  
  118. plays at that level until you release
  119.  
  120. the key. Then it quickly dies away.
  121.  
  122.   The volume of the violin increases
  123.  
  124. as you begin to move the bow, holds
  125.  
  126. near peak volume as you bow it, and
  127.  
  128. then gradually the strings stop
  129.  
  130. vibrating after you lift the bow.
  131.  
  132.   The piano produces a loud sound
  133.  
  134. when the hammer hits the wires, but
  135.  
  136. the volume quickly dies to a lower
  137.  
  138. level and stays at about that level
  139.  
  140. until you release the key.  Then the
  141.  
  142. vibrations of the wire are quickly
  143.  
  144. damped out.
  145.  
  146.               ----
  147.  
  148.   So, how does ADSR relate to all
  149.  
  150. this talk of instruments and
  151.  
  152. envelopes?  Like this:
  153.  
  154.   ATTACK is the leading edge of the
  155.  
  156. envelope -- how long it takes the
  157.  
  158. sound to reach its peak volume.  The
  159.  
  160. attack of an organ is very fast --
  161.  
  162. the sound builds up immediately.
  163.  
  164.   DECAY begins as soon as the peak
  165.  
  166. volume is reached.  In an instrument
  167.  
  168. like the organ or violin, where
  169.  
  170. energy is being continuously pumped
  171.  
  172. into each note, the volume won't
  173.  
  174. decay much at all.  In the piano, all
  175.  
  176. the energy was delivered by one blow
  177.  
  178. of the hammer, and the strings
  179.  
  180. rapidly lose much of their energy
  181.  
  182. (energy = sound volume).
  183.  
  184.   SUSTAIN begins where decay leaves
  185.  
  186. off.  This is the equilibrium volume
  187.  
  188. of the instrument.  In an organ, it
  189.  
  190. would be full volume, because there
  191.  
  192. is no decay.  In a piano, it's the
  193.  
  194. volume sustained by a note while you
  195.  
  196. hold the key down.  The SID chip's
  197.  
  198. sustain is a constant level.  In real
  199.  
  200. life, a piano loses volume while in
  201.  
  202. the sustain part of the waveform.  As
  203.  
  204. I said earlier, these envelopes are
  205.  
  206. just reasonable approximations of the
  207.  
  208. real thing.
  209.  
  210.   RELEASE is what happens when the
  211.  
  212. musician stops playing a note.  On an
  213.  
  214. organ, as soon as you release the key
  215.  
  216. the volume drops to nothing (except
  217.  
  218. for reverberations -- they're
  219.  
  220. something SID can't handle).  It has
  221.  
  222. a very short release.  A xylophone,
  223.  
  224. on the other hand, dies out
  225.  
  226. gradually.  It has a long release
  227.  
  228. (unless you damp it with your hand.)
  229.  
  230.         --------------------
  231.         HOW SID HANDLES ADSR
  232.         --------------------
  233.  
  234.   Believe it or not, SID treats ADSR
  235.  
  236. just like I described it above.  The
  237.  
  238. values for attack, decay, sustain,
  239.  
  240. and release can range from a minimum
  241.  
  242. of 0 to a maximum of 15.
  243.  
  244.   Attack time will range from 2
  245.  
  246. milliseconds to 8 seconds, decay from
  247.  
  248. 6 ms to 24 seconds, and release from
  249.  
  250. 6 ms to 24 seconds. The sustain level
  251.  
  252. ranges from 0/15 to 15/15 of the
  253.  
  254. volume.
  255.  
  256. -------------------------------------
  257. HOW DO YOU TELL SID WHAT ADSR TO USE?
  258. -------------------------------------
  259.  
  260.   You set ADSR for each SID voice
  261.  
  262. individually by POKEing ADSR values
  263.  
  264. into two adjacent memory locations as
  265.  
  266. follows:
  267.           A&D   S&R
  268.           ----------
  269. Voice 1:  S+5   S+6
  270. Voice 2:  S+12  S+13
  271. Voice 3:  S+19  S+20
  272.  
  273.   The way you get both attack and
  274.  
  275. decay or sustain and release into the
  276.  
  277. same byte is via formulae like these:
  278.  
  279.  AD = A*16+D : SR = S*16+R
  280.  POKE S+5,AD : POKE S+6,SR
  281.  
  282.   Now let's look at some examples
  283.  
  284. that might simulate the envelopes we
  285.  
  286. drew for the organ, violin, and
  287.  
  288. piano.
  289.  
  290.               ----
  291. ORGAN
  292.  Fast attack        =  0
  293.  No decay           =  0
  294.  High level sustain = 15
  295.  Fast release       =  0
  296.  
  297.   AD = 0*16+0 : SR = 15*16+0
  298.   POKE S+5,AD : POKE S+6,SR
  299.  
  300.               ----
  301. VIOLIN
  302.  Moderate attack    =  4
  303.  Slow decay         =  7
  304.  High level sustain = 12
  305.  Slow release       =  7
  306.  
  307.   AD = 4*16+7 : SR = 12*16+7
  308.   POKE S+12,AD: POKE S+13,SR
  309.  
  310.               ----
  311. PIANO
  312.  Moderate attack    =  3
  313.  Moderate decay     =  4
  314.  Mid level sustain  =  8
  315.  Moderate release   =  5
  316.  
  317.   AD = 3*16+4 : SR = 8*16+7
  318.   POKE S+19,AD: POKE S+20,SR
  319.  
  320.               ----
  321.  
  322.   How did I arrive at those particular
  323.  
  324. values for ADSR?  Easy!  I just
  325.  
  326. guessed.  The best way to make an
  327.  
  328. educated guess is to use a tool that
  329.  
  330. will play a note with any envelope you
  331.  
  332. design.  We supply you with such a
  333.  
  334. tool:  The AWG ADSR TOY. (It's this
  335.  
  336. month's example program.)
  337.  
  338.   If you want to play around with
  339.  
  340. designing your own ADSR envelopes,
  341.  
  342. run this month's sample program by
  343.  
  344. pressing the "\" key now (the British
  345. \oad"awg adsr toy",8
  346. Pound sign).
  347.  
  348.  
  349. ---------< end of article >-----------
  350.